package com.ict.controller;


import com.ict.api.dto.IctRoleDTO;
import com.ict.api.result.ApiResponse;
import com.ict.api.vo.IctRoleVO;
import com.ict.service.IctRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author wjp
 * @since 2025-03-23
 */
@RestController
@RequestMapping("/ict-role")
public class IctRoleController {
    @Autowired
    private IctRoleService roleService;

    /**
     * 分配用户角色
     * @param id 用户id
     * @param roleDTO 角色或状态
     * @return ApiResponse
     */
    @PostMapping("/users/{id}")
    public ApiResponse setUserRoles(@PathVariable Long id, @RequestBody IctRoleDTO roleDTO) {
        roleService.setUserRoles(id, roleDTO);
        return ApiResponse.success();
    }

    /**
     * 删除用户角色
     * @param id 用户id
     * @param roleDTO 角色或状态
     * @returne ApiResponse
     */
    @DeleteMapping("/users/{id}")
    public ApiResponse deleteUserRoles(@PathVariable Long id, @RequestBody IctRoleDTO roleDTO) {
        roleService.deleteUserRoles(id, roleDTO);
        return ApiResponse.success();
    }

    @GetMapping("/roles")
    public ApiResponse getRoles() {
        List<IctRoleVO> roleVoList = roleService.getRoles();
        return ApiResponse.success(roleVoList);
    }

}

